import { _decorator, Component, Node, Button, Label, Sprite, resources, SpriteFrame } from 'cc';
import { Equitment } from '../Equitment';
import { EventManager } from '../EventManager';
import { EventType } from '../EventType';
import { UIOpenChest } from './UIOpenChest';
const { ccclass, property } = _decorator;

@ccclass('UIChestItem')
export class UIChestItem extends Component {
    public EquitID:number = -1
    @property(Button)
    public SelfBtn:Button
    @property(Label)
    public Name:Label
    @property(Label)
    public Comment:Label
    @property(Sprite)
    public Icon:Sprite

    start()
    {
        this.SelfBtn.node.on(Button.EventType.CLICK, this.OnClickBtn, this)
    }

    SetConfig(Equitment:Equitment)
    {
        this.EquitID = Equitment.ID
        this.Name.string = Equitment.Name
        this.Comment.string = Equitment.Comment
        this.node.active = false
        resources.load("Icon/" + Equitment.Icon+"/spriteFrame", SpriteFrame, (err, sp) => {
            this.Icon.spriteFrame = sp
            this.node.active = true
        });
    }

    OnClickBtn()
    {
        EventManager.instance.DispatchEvent(EventType.EquitmentSelect, this.EquitID)
    }

    onDestroy()
    {
        //this.SelfBtn.node.off(Button.EventType.CLICK, this.OnClickBtn, this)
    }
}


